package com.reremouse.util;

import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class JsfHelper {
    public static <T> T getBean(String beanName) {
        Object bean = null;
        FacesContext context = FacesContext.getCurrentInstance();
        bean = context.getApplication().getVariableResolver().resolveVariable(context, beanName);
        return (T) bean;
    }

    public static <T> T getBean(FacesContext fc, String beanName) {
        Object bean = null;
        bean = fc.getApplication().getVariableResolver().resolveVariable(fc, beanName);
        return (T) bean;
    }

    public static HttpServletRequest getRequest() {
        HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
        return req;
    }

    public static HttpServletResponse getResponse() {
        HttpServletResponse req = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
        return req;
    }

    public static <T> T resolveVariable(FacesContext context, String v) {
        T bean = null;
        bean = (T) context.getApplication().createValueBinding(v).getValue(context);
        return bean;
    }
}



/* Location:           F:\jsp源码\蝙蝠论坛系统\rerebbs\WEB-INF\classes\

 * Qualified Name:     com.reremouse.util.JsfHelper

 * JD-Core Version:    0.7.0.1

 */